
<!------------------------------- CONTENT --------------------------------->
<div>
	<!-- Start wrap content -->
	<div class="wrap-section detail-info" id="section-manga">
    		<div style="max-width: 1000px; margin: auto; background-color: #fafafa; padding: 0px; border-radius: 0px; margin-bottom: 0px">
			<ul xmlns:v="http://rdf.data-vocabulary.org/#"
				class="breadcrumb chap_footer_breadcrumb"
				style="padding: 5px; margin: 0px">
				<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title"
					href="<?php echo HOME ?>"><i class="fa fa-home"></i> </a></li>
				<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title"
					href="<?php echo MANGA_URL ?>">Truyện Tranh</a></li>
				<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title"
					href="<?php echo mangaf1_url_manga($data['id'],$data['alias']); ?>"><?php echo short_str($data['name'],25); ?>
				</a></li>
				<li typeof="v:Breadcrumb"><?php echo $data['ep']['ten']; ?></li>
			</ul>
		</div>
		<h1
			style="padding: 5px; font-size: 20px; font-weight: lighter; text-align: center; color: #000">
			<?php echo $data['name'].' '; ?>
			<?php echo str_ireplace('Chapter','Chap',$data['ep']['ten']).' '; ?>
			| Đọc Truyện
			<?php echo $data['name'].' '; ?>
			<?php echo  str_ireplace('Chapter','Chap',$data['ep']['ten']).' '; ?>
			Tiếng Việt
		</h1>

		<!--------------------------------Main Content---------------------------------->
		<div class="row" style="max-width: 800px; margin: auto">
			<div class="col-md-4 col-xs-2" style="text-align: right">
				<button class="btn  btn-hot" type="button" onclick="previouschap()">
					<i class="fa fa-arrow-left"></i>
				</button>
			</div>
			<div class="col-md-4 col-xs-8">
				<select class="form-control" data-placeholder="Chọn Chapter..."
					id="chapters" name="chapters" style="width: 100%"
					onchange="location.href=this.value">
					<?php
					foreach($data['chapters'] as $row1){
									 echo "<option value='".mangaf1_url_manga_episode($row1['id'],$row1['seourl']) ."'";
									 if($row1['id']==$_GET['id']){
echo " selected ";
}
echo ">";
echo $row1['ten'];
echo "</option>";
									}
									?>
				</select>
			</div>
			<div class="col-md-4 col-xs-2">
				<button class="btn  btn-hot" type="button" onclick="nextchap()">
					<i class="fa fa-arrow-right"></i>
				</button>
			</div>
			
			<div class="col-md-12">
				<p id="load-type" style="text-align:center; margin-top: 8px;">Chọn kiểu load:  &nbsp;
					<input id="loadType1" class="loadType" type="checkbox" value="1" name="loadType" /> Lần lượt &nbsp;
					<input id="loadType2" class="loadType" type="checkbox" value="2" name="loadType" /> Toàn bộ
				</p>
				<script type="text/javascript">
					$(document).ready(function(){
						if($.cookie('load_type')){
							$('#load-type').find('#loadType'+$.cookie('load_type')).prop('checked', true);
						}
						
						$('.loadType').on('change', function(){
							if($(this).is(':checked') == true){
								$('.loadType').prop('checked',false);
								$(this).prop('checked', true);
								$.cookie('load_type', $(this).attr('value'), { expires: 30 });
								
							}else{
								$.removeCookie('load_type');
								
							}
							window.location.href = document.URL;
							
						});
					});
				</script>
			</div>
		</div>
	</div>
	<!-- End col 12 -->
</div>
<!-- End of row -->
<!-- Chapter content -->
<div class="section-content"
	id="manga-chapt-wrapper">
	<div role="tabpanel" class="chapt-detail-tab"
		id="manga-chapt-detail-tab">
		<div class="wrap-manga-chapt-tab-header">
			<ul class="nav nav-pills">
				<li role="presentation" class="active"><a data-toggle="tab"
					href="#manga-chapt-detail-tab-read">Đọc truyện</a></li>
				<li role="presentation"><a data-toggle="tab"
					href="#manga-chapt-detail-tab-comment">Thảo luận</a></li>
				<?php if(count($data['related'])>0){?>
				<li role="presentation"><a data-toggle="tab"
					href="#manga-chapt-detail-tab-info">Truyện Liên Quan <span
						class="badge"><?php echo count($data['related']); ?> </span>
				</a></li>
				<?php }?>
			</ul>
		</div>
		<div class="tab-content" id="manga-chapt-detail-content">
			<div class="tab-pane active fade in" id="manga-chapt-detail-tab-read">
				<h1
					style="padding: 5px; font-size: 19px; text-align: center; color: #FFF">
					<?php $name= $data['name']." ".str_ireplace('Chapter','Chap',$data['ep']['ten']); ?>
					<?php echo $name; ?>
				</h1>
				
			
						
						         <?php
									 $str2='';
									 foreach($data['ep']['chapter_link'] as $item){
									 	$str2.=$item."|";
									 }
									 $str2 = substr($str2,0,-1);
								
								 echo '<div class="chapcontent" id="chapcontent"></div>';
								?>
                                  	<script>  
										$(document).ready(function(){
												$('.chapcontent').append('<div class="image-load" style="text-align:center"><img src="http://image.manga24h.com/upload/images/2014/07/11/loading.gif" /></div>');
						
													data='<?php echo $str2; ?>';
												  	images = new Array();
													images = data.split("|");
													Loadimage(0);
											  
									   
										
							})
						
		
		   function Loadimage(i)
        	{
           		if(i<images.length)
          	 {
				
               var img = new Image();
               img = '<div  style="z-index:500;"><img src="' + images[i] + '"   style="border:3px solid #fff; margin:auto;z-index:500" class="img-responsive"></div><br/>';
			   
			   $('.image-load').remove(); 
               $('.chapcontent').append(img);
               i++;
			  
				if(i<images.length){
			  	$('.chapcontent').append('<div class="image-load" style="text-align:center"><img src="http://image.manga24h.com/upload/images/2014/07/11/loading.gif" /></div>');
				}
				var load_type = $.cookie('load_type');
				if(!load_type) load_type = 1;
				
				if(load_type == 1){
			  setTimeout(function(){
  //where we can also call foo
				Loadimage(i);
				},2000);
				}else{
				Loadimage(i);	
				}
              
            } else {
             
            }
        }
        </script>
		
				<!-- Start footer chapter nav -->
				<div class="row" style="max-width: 1000px; margin: auto; padding-top:10px">
					<div class="col-md-8 col-xs-12">
						<div class="row" style="margin-bottom: 10px">
							<div class="col-md-2 col-xs-3" style="text-align: right">
								<button class="btn  btn-hot btn-md" type="button"
									onclick="previouschap()">
									<i class="fa fa-arrow-left"></i>
								</button>
							</div>
							<div class="col-md-6 col-xs-6">
								<select class="form-control" data-placeholder="Chọn Chapter..."
									id="chapters" name="chapters" style="width: 100%"
									onchange="location.href=this.value">
									<?php
									foreach($data['chapters'] as $row1){
                                                     echo "<option value='".mangaf1_url_manga_episode($row1['id'],$row1['seourl']) ."'";
                                                     if($row1['id']==$_GET['id']){
echo " selected ";
}
echo ">";
echo $row1['ten'];
echo "</option>";
                                                    }
                                                    ?>
								</select>
							</div>
							<div class="col-md-2 col-xs-3" style="text-align: left">
								<button class="btn  btn-hot btn-md" type="button"
									onclick="nextchap()">
									<i class="fa fa-arrow-right"></i>
								</button>
							</div>
						</div>
						<!-- End row -->
					</div>
					<!--End col-md-8 -->
					<div class="col-md-4 col-xs-12" style="text-align: left">
						<a class="report_truyen btn btn-fresh"> <span
							class="glyphicon glyphicon-warning-sign"></span> Báo Lỗi
						</a> &nbsp;&nbsp; <a class="note_story btn btn-fresh"> <span
							class="glyphicon glyphicon-bookmark"></span>Theo Dõi
						</a>
					</div>
				</div>
				<!-- End row -->
				<Br /> <Br />
				<!-- End footer chapter nav -->
			</div>
			<!-- End tab read manga -->
			<div class="tab-pane fade in" id="manga-chapt-detail-tab-comment"></div>
			<!-- End tab comment -->
			<?php if(count($data['related'])>0){?>
			<div class="tab-pane fade in" id="manga-chapt-detail-tab-info">
				<div style="max-width: 800px; margin: auto;">
					<?php echo manga_render_related_manga($data['related']); ?>
				</div>
			</div>
			<!-- End tab comment -->
			<?php }?>
		</div>
		<!-- End tab content -->
	</div>
	<!-- End tabpanel-->
</div>
<!-- /.section-content -->
</div>
<!-- /#section-manga -->
<!-- Start footer chapter Information -->
<div class="clearfix"></div>
<div class="wrap-manga-chapt-comment">
	<div
		style="max-width: 1000px; margin: auto; background-color: #fff; padding: 0px; border-radius-bottom-left:5px;border-radius-bottom-right:5px">
		<ul class="breadcrumb chap_footer_breadcrumb"	style="padding: 5px; margin: 0px; border-radius:0px">
			<li><a href="<?php echo HOME ?>"><i class="fa fa-home"></i> </a></li>
			<li><a href="<?php echo HOME ?>">Truyện Tranh</a></li>
			<li><a
				href="<?php echo mangaf1_url_manga($data['id'],$data['alias']); ?>"><?php echo short_str($data['name'],15); ?>
			</a></li>
			<li><?php echo $data['ep']['ten']; ?></li>
		</ul>
		<div class="footer_chap_block" style="padding:0px">
        
        <?php //GET USER INFOR
		if($data['ep']['uploader']!=''){
		 	$val_user=get_user_by_username($data['ep']['uploader']);
		 	if($val_user){
				//Show user infor ---------
				?>
                			<div class="user-pad" id="chapt-detail-user-info">
		
				<div class="row">
					<div class="col-md-9">
						<div class="panel-title blog-detail-user-title">
							<a class="blog-title-avatar" href="#"><img src="<?php echo $val_user['avatar']; ?>"	alt=""> </a>
							<div class="blog-title-user-info">
								<p class="blog-title-username" style="font-weight: lighter; font-size:20px; padding-bottom:5px">
									<?php echo show_username($val_user['username'],$val_user['name']); ?><br>
								</p>
							   <p class="status">
                               	<i class="fa fa-quote-left"></i> <em> <?php if($val_user['slogan']!=''){ echo $val_user['slogan'];}else{ echo "No Status";} ?> </em><i class="fa fa-quote-right"></i>
                                </p>
								   <?php if($val_user['facebook_url']!=''){?> <p class="user-metadata"><a href="<?php echo $val_user['facebook_url']; ?>" target="_blank"><i class="fa fa-facebook-square"></i> Facebook </a></p><?php }?>
                                   
								<p class="user-metadata" style="display:none">
									<i class="fa fa-group"></i> Group: <span
										style="font-weight: lighter; font-size:18px"><?php echo get_user_group_name($val_user['group_id']); ?></span>
								</p>
								<div class="clr"></div>
						
							</div>
							<div class="clr"></div>
						</div>
						<div class="clr"></div>
					</div>
					<div class="col-md-3">
						<div style="text-align: center; font-weight: lighter;">
							<span style="font-size: 14px;">Ngày đăng:</span>
							<p style="font-size: 24px;"><?php echo $data['ep']['ngaythem']; ?></p>
						</div>
					</div>
					
                    <?php if($val_user['chuky']!=''){?>
					<div class="col-md-12">
						<div style="padding: 10px; background: #0066a0; background-color:#fff; border-top:2px solid #F60">
                        	<?php echo BBCode::parse($val_user['chuky']); ?>
                        </div>
					</div>
                    <?php } ?>
				</div>	<!-- .row -->
			</div>  <!-- user-pad -->
                <?php
			}
				//End show user infor-------
		}
		 ?>
        
		
			<div class="page-header hidden-xs" style="padding:10px">
			
			
				<div class='alert alert-warning' style="font-weight:lighter; font-size:20px;">
				<small> 	Click Like và Comment Nhiệt Tình để ủng hộ nhóm dịch và
						editor, cũng như uploader nào ^^</small>
                        <div class="addthis_native_toolbox"></div>
				</div>
                	
			</div>
			<!-- Start disqus-->
				<div style="background-color:#fff; padding:5px">
                                  		 <div id="disqus_thread"></div>
										<script type="text/javascript">
                                            /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
                                            var disqus_shortname = 'truyencuatui'; // required: replace example with your forum shortname
                                    
                                            /* * * DON'T EDIT BELOW THIS LINE * * */
                                            (function() {
                                                var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                                                dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
                                                (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
                                            })();
                                        </script>
                                        <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
                            </div>
		<!-- End disqus -->
			<div class="hidden-xs" style=" padding:15px; line-height:20px">
				<b><i class="fa fa-tag"></i> Tags :</b>
				<?php echo $data['ep']['data_tags']?>
				<div class="visible-xs" style="font-size:14px; font-weight:lighter;">
					<?php echo $data['tag3']; ?>
				</div>
			</div>
			<div class="hidden-xs" style="font-size: 15px; font-weight:lighter; padding:10px">
				Bạn đang đọc <b><?php echo $data['name']; ?> <?php echo $data['ep']['ten']; ?>
				</b> tại website <a href="<?php echo HOME;?>truyentranh/">đọc truyện tranh
					online </a>hàng đầu việt nam Truyencuatui.info. Trong quá trình đọc
				truyện bạn có thể sử dụng chức năng theo dõi chapter để lưu lại lịch
				sử đọc truyện (chỉ dành cho thành viên đã đăng nhập) , hoặc chức
				năng báo lỗi nếu chapter bị hỏng để ban quản trị fix chapter nhanh
				nhất . Nếu bạn tham gia thảo luận sau khi đọc <b><?php echo $data['name']; ?>
					<?php echo $data['ep']['ten']; ?> tiếng việt</b> , xin vui lòng
				không chửi bới, xúc phạm người khác, nhóm dịch hoặc hối chapter mới
				nhé.
			</div>
		</div>
		<!-- End footer chap block -->
	</div>
	<!-- End wrap 800px -->
</div>
<!-- /.wrap-manga-chapt-comment -->

<script type="text/javascript">
	$(document).ready(function(){
			contentImage = $('#chapcontent').find('.lazy');
			if(contentImage){
				$.each(contentImage, function(ii, vv){
					imgSrc = $(vv).attr('src');
					$(vv).attr('src','<?= HOME ?>public/images/loading.gif');
					$(vv).attr('data-original', imgSrc);
					//vv.attr('src','');
					//vv.attr('data-original', imgSrc);
					
				});
			}
			
		
			 $('.report_truyen').on('click',function(e){
			 	/*
			 	Truyền vào truyen_id, truyen_chuong_id, url, noidung
			 	*/
				e.preventDefault();
				
				//dataHref = window.location.pathname;
				//truyen_id = $(this).parent().parent().parent().attr('data-rel');
				
				if(!$('#modal_truyen_report').length){
					$.ajax({
						url: baseUrl + 'index.php?module=ajax&act=manga&opt=modal&get_modal_truyen_report=1',
						type: 'POST',
						success: function(data){
							$('body').append(data);
							$('#modal_truyen_report').modal();
							//$('#modal_report').show();
						}
					});
					
				}else{
					$('#modal_truyen_report').modal();
				}
			});
		 $('.submit_truyen_report').on('click', function(e){
				e.preventDefault();
				truyen_id = '<?= $data['id']; ?>';
				truyen_chuong_id = '<?= $data['ep']['id']; ?>';
				url = document.URL;
				
				$(".alert").remove();
				$.ajax({
					url: baseUrl + 'index.php?module=ajax&act=manga&opt=report&send_truyen_report=1',
					type: 'POST',
					data: { 
						txt_report_content: $('#txt_report_content').val(),
						truyen_id: truyen_id,
						truyen_chuong_id: truyen_chuong_id,
						url: url
					},
					
					success: function(data){
						if(data) newData = JSON.parse(data);
						console.log(newData);
						if(newData.errors){
		    				$.each(newData.errors, function(e, error){
			    				if(e != 'error'){
			    					$('#' + e).parent().append('<div id="'+e+'_error" class="alert alert-danger alert-dismissable" style="display: none;"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+error+'</div>');
			    					$('#' + e + '_error').slideDown('fast');
			    				}else{
									
			    				}
		    				});
						}else if(newData.message){
							
							//console.log($('#txt_report_content_' + $(this).attr('data-href')).val());
							$('#modal-content').append('<div id="report_success" class="alert alert-success alert-dismissable" style="display:none;">Cám ơn bạn đã báo cáo nội dung xấu. Chúng tôi sẽ kiểm tra bài viết trong thời gian sớm nhất.</div>');
							//$('#report_success').slideDown('fast');
							var test = $('#report_success').slideDown('fast').delay(1000).slideUp('fast', function(){$('#modal_truyen_report').modal('hide');});
							$('#txt_report_content').val('');
							
						}
					}
				});
			});
			$('.note_story').on('click',function(e){
				e.preventDefault();
				username = '<?= $_SESSION['user']['username']; ?>';
				if(!username){
					//window.location.href = '<?= LOGIN ?>';
						popupMessage('Chưa Đăng Nhập', ['Hãy đăng nhập để có thể theo dõi truyện này'], 'alert-danger');
					return;
				}
				id = '<?= $data['ep']['id']; ?>';
				truyen_id = '<?= $data['id']; ?>';
				ten = '<?= $data['ep']['ten']; ?>';
				url = '<?php echo url(); ?>';
				username = '<?= $_SESSION['user']['username']; ?>';
				
				$.ajax({
					url: 'index.php?module=ajax&act=manga&opt=follow_story&note_chapt=1',
					type: 'POST',
					data: {id: id,truyen_id: truyen_id, ten: ten, url: url, username: username},
					success: function(data){
						if(data) newData = $.parseJSON(data);
						if(newData.error){
							popupMessage('Lỗi', [newData.error], 'alert-danger');
						}else if(newData.message){
							popupMessage('Thành công', ["Bạn đã đăng ký theo dõi manga này thành công"], 'alert-success');
						}
					},
				});
			});
		
		
	});
	
</script>
<script>
function previouschap()
	{	
	
		lch=eval(document.getElementById('chapters').length);
		ch=document.getElementById('chapters').value;
		
			index=document.getElementById('chapters').selectedIndex;     //lay index chapter hien tai
			fch=document.getElementById('chapters')[lch-1].value;    //gia tri cua chapter cuoi
			if(ch==fch)												// neu chapter hien tai == chapter cuoi							
			{ 
			 alert('Bạn đã xem chapter  đầu tiên rồi !!');
			}
			else
			{
				nextch = document.getElementById('chapters')[index+1].value; //lay gia tri cua chapter tiep theo
				location.href=nextch;
						
			}
	
	
	}
	
	function nextchap()
	{	
	
		lch=eval(document.getElementById('chapters').length);
		ch=document.getElementById('chapters').value;
		
			index=document.getElementById('chapters').selectedIndex;     //lay index chapter hien tai
			fch=document.getElementById('chapters')[0].value;    //gia tri cua chapter cuoi
			if(ch==fch)												// neu chapter hien tai == chapter cuoi							
			{ 
			 alert(' Hiện tại bã đã xem đến chapter mới nhất của bộ truyện !! \nChapter mới  hơn sẽ được chúng tôi update trong thời gian sớm nhất nếu có :))')
			}
			else
			{
				nextch = document.getElementById('chapters')[index-1].value; //lay gia tri cua chapter tiep theo
				location.href=nextch;
						
			}
	
	
	}
   
 </script>
